﻿@using System.Collections.Generic;
@using hc.epm.DataModel.Business;
@using hc.epm.Common;
@using hc.Plat.Common.Extend;
@model Epm_Project
@{
    ViewBag.Title = "IsCrossingsManage";
}
<style>
    input[type="text"] {
        padding-left: 15px;
    }

    .long-text-other input {
        height: 35px;
        margin-bottom: 15px;
        border: 1px solid #C7C7C7;
        box-sizing: border-box;
    }

    .addother {
        width: 100px;
        height: 25px;
        margin-left: 124px;
        margin-bottom: 15px;
        font-size: 16px;
    }

    .inputone {
        display: inline-block;
        height: 30px;
        width: 108px !important;
        line-height: 30px;
        border: 1px solid #C7C7C7;
        box-sizing: border-box;
        margin-bottom: 15px;
    }

    .inputTwo {
        display: inline-block;
        box-sizing: border-box;
        padding-left: 15px;
        height: 30px;
        line-height: 30px;
        border: 1px solid #C7C7C7;
        border-radius: 1px;
        margin-bottom: 15px;
    }

    .default {
        background: #ebebe5;
    }
</style>
<div class="contentData">
    <form>
        <ul class="tab-list">
            <li id="Edit">基本信息</li>
            <li id="ApprovalConstitute">总批复构成</li>
            <li id="ProjectISP">工程供应商</li>
            <li id="ProjectMainPoint">工程要点</li>
            <li id="MilestonePlan">工程节点</li>
            <li id="TimeManage">工期管理</li>
            @*<li id="ProjectData">项目资料</li>*@
            <li id="IsCrossingsManage" class="active">外部手续</li>
        </ul>
        <div class="tab">
            <div class="long-text">
                <label><span class="star">*</span>&nbsp;外部手续&nbsp;:</label>
                @if (ViewBag.IsCrossings == null || ViewBag.IsCrossings == false)
                {
                    <input type="radio" class="Crossings" name="Crossings" value="1" />@Html.Raw("办理");
                    <input type="radio" class="Crossings" name="Crossings" value="0" checked />@Html.Raw("无");
                }
                else
                {
                    <input type="radio" class="Crossings" name="Crossings" value="1" checked />@Html.Raw("办理");
                    <input type="radio" class="Crossings" name="Crossings" value="0" />@Html.Raw("无");
                }
                <input type="hidden" id="IsCrossings" name="IsCrossings" />
            </div>
            <div class="upload" style="margin-bottom:0px;">
                <div><label><span class="star">*</span>&nbsp;外部手续附件&nbsp;:</label></div>
                <div class="btn-upload">
                    <input type="button" id="btnUploadFile" style="position: relative; z-index: 1;" value="上传附件" />
                    <input type="file" id="loadFile" name="loadFile" style="display:none" onchange="uploadFile()">
                </div>
            </div>
            <div style="width:100%;" id="fileListFile">
                <ul class="fileShow"></ul>
                <input type="hidden" name="fileDataJsonFile" id="fileDataJsonFile">
            </div>
            <div class="button-group btn-center">
                <button type="button" class="saveBut " id="saveBut" data-module="ConProject" data-right="SetConstitute">保存</button>
            </div>
        </div>
    </form>
</div>
<script src="~/Resource/plugins/layui-2.1.2/lay/modules/layer.js"></script>
<script>

    //获取附件
    $.post("/Files/GetFileList", { tableName: 'Epm_Project', id: '@ViewBag.ProjectId', tableCol: "Constitute" }, function (data) {
        if (data.Flag) {
            if (data.Data.length > 0) {
                data.Data.forEach(function (item, index, arr) {
                    if (item.ImageType == null) {
                        var odiv = '<li id="' + item.GuidId + '">';
                        odiv += '<div class="downloadFile"><img src="' + getFileImg(item.Name) + '" style="width: 20px;height: 20px;cursor: pointer;" class="imgShow"/><a href="javascript:;" target="_blank">' + item.Name + '</a></div>';
                        odiv += '<div>' + item.Size + '</div>';
                        odiv += '<span style="margin-left:20px;">' + item.CreateUserName + '</span>';
                        odiv += '<span style="margin-left:20px;">' + new Date(formatDateByJson(item.CreateTime)).Format("yyyy-MM-dd") + '</span>';
                        odiv += '<span style="margin-left:30px;cursor: pointer;color:blue" class="fileDel" data-val="' + item.GuidId + '">删除</span>'
                        odiv += '</li>';
                        $('#fileListFile .fileShow').append(odiv);
                    }

                    var obj = {};
                    obj.Name = item.Name;
                    obj.GuidId = item.GuidId;
                    obj.Size = item.Size;
                    obj.Group = item.Group;
                    obj.Url = item.Url;
                    obj.TableColumn = item.TableColumn;
                    obj.ImageType = item.ImageType;
                    fileDataArray.push(obj);
                });
                var fileDataJsonFile = JSON.stringify(fileDataArray);
                $("#fileDataJsonFile").val(fileDataJsonFile);
            }
        } else {
            parent.layer.alert(data.Message, { icon: 2 });
        }
    });

    var fileDataArray = [];
    function uploadFile() {
        if ($("#loadFile")[0].files.length == 0) {
            return;
        }
        var fileObj = $("#loadFile")[0].files[0]; // js 获取文件对象
        var formFile = new FormData();
        formFile.append("file", fileObj);
        var path = formFile;

        $.ajax({
            url: "/Upload/UploadHB",
            type: "POST",
            data: path,
            contentType: false,
            processData: false,
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var obj = {};
                    obj.Name = data[i].Name;
                    obj.GuidId = data[i].GuidId;
                    obj.Size = data[i].Size;
                    obj.ImageType = data[i].ImageType;
                    obj.Group = data[i].ResponseObject.FDFS_GROUP;
                    obj.Url = data[i].ResponseObject.FDFS_NAME;
                    obj.TableColumn = "Constitute";
                    fileDataArray.push(obj);

                    if (data[i].ImageType == null) {
                        var imgUrl = getFileImg(obj.Name);
                        var odiv = '<li id="' + obj.GuidId + '">';
                        odiv += '<div><img src="' + imgUrl + '" style="width: 20px;height: 20px;cursor: pointer;" class="imgShow"/><a href="javascript:;" target="_blank">' + obj.Name + '</a></div>';
                        odiv += '<div style="text-align:right; width:80px;">' + obj.Size + '</div>';
                        odiv += '<span style="margin-left:20px;">' + data[i].UploadName + '</span>';
                        odiv += '<span style="margin-left:20px;">' + new Date(formatDateByJson(data[i].UploadDate)).Format("yyyy-MM-dd") + '</span>';
                        odiv += '<span style="margin-left:20px;cursor: pointer;color:blue" class="fileDel" data-val="' + obj.GuidId + '">删除</span>'
                        odiv += '</li>';
                        $('#fileListFile .fileShow').append(odiv);
                    }
                }
                fileDataJson = JSON.stringify(fileDataArray);
                $("#fileDataJsonFile").val(fileDataJson);
            }
        });
    }

    $(".Crossings").click(function () {
        if ($(".Crossings:checked").val() == 1) {
            $(".upload").show();
        } else {
            $(".upload").hide();

            $('#fileListFile .fileShow').empty();
            $("#fileDataJsonFile").val("[]");

        }
    });

    $(function () {
        $('#btnUploadFile').click(function () {
            document.getElementById("loadFile").click();
        });

        if ($(".Crossings:checked").val() == 1) {
            $(".upload").show();
        } else {
            $(".upload").hide();
        }
    });

    $(document).ready(function () {
        $("#Edit").click(function () {
            window.location.href = 'Edit?projectId=@ViewBag.ProjectId';
        });
        $("#ProjectMainPoint").click(function () {
            window.location.href = 'ProjectMainPoint?projectId=@ViewBag.ProjectId';
        });
        $("#TimeManage").click(function () {
            window.location.href = 'TimeManage?projectId=@ViewBag.ProjectId';
        });
        $("#MilestonePlan").click(function () {
            window.location.href = 'MilestonePlan?projectId=@ViewBag.ProjectId';
        });
        $("#ProjectISP").click(function () {
            window.location.href = 'ProjectISP?projectId=@ViewBag.ProjectId';
        });
        $("#ProjectData").click(function () {
            window.location.href = 'ProjectData?projectId=@ViewBag.ProjectId';
        });
        $("#ApprovalConstitute").click(function () {
            window.location.href = 'ApprovalConstitute?projectId=@ViewBag.ProjectId';
        });
        $("body").on("click", ".dynamicAdd", function () {
            $(this).parent().find("input[type='text']").addClass("default").attr({ readonly: 'true' });
            $(this).hide();
            $(this).parent().find(".dynamicEdit").show();
        });
        $("body").on("click", ".dynamicEdit", function () {
            $(this).parent().find("input[type='text']").removeClass("default").removeAttr("readonly");
            $(this).hide().parent().find(".dynamicAdd").show();
        });
        //删除附件
        $("#fileListFile").on("click", ".fileDel", function () {
            $(this).parents("li").remove();
            var toremove = '';
            var id = $(this).data("val");
            //----删除初始文件对应的值
            fileDataArray = fileDataArray.filter(function (item, index, arr) {
                return item.GuidId != id
            })
            var fileDataJsonFile = JSON.stringify(fileDataArray);
            $("#fileDataJsonFile").val(fileDataJsonFile);
        });
        //数据提交
        $("#saveBut").click(function () {
            if ($(".Crossings:checked").val() == 1) {
                $("#IsCrossings").val("true");

                var filesList = $("#fileDataJsonFile").val();
                if (filesList == "") {
                    layer.alert("请上传外部手续附件", { icon: 2 });
                    return false;
                }
            } else {
                $("#IsCrossings").val("false");
            }
            var search = $("form").serialize();
            $.post("CrossingsManage?projectId=@ViewBag.ProjectId", search, function (data) {
                if (data.Flag) {
                    layer.msg("操作成功", { time: 1000, icon: 1 }, function () {
                        window.location.href = "/Project/Index";
                        window.location.reload();
                    });
                } else {
                    layer.alert(data.Message, { icon: 2 });
                }
            });
        });
    });
</script>